/**
 * 详情对话框
 */
var BannerInfoDlg = {
    data: {
        title: "",
        image: "",
        content: "",
        url: "",
        isVideo:"",
        goodsId: "",
        weigh: "",
        isBanner: "",
        status: "",
        adminId: "",
        linkWay: "",
        createTime: "",
        updateTime: ""
    },
    editor:null,
};

layui.use(['form', 'admin', 'ax','upload',"simTool"], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var upload = layui.upload;
    var simtool = layui.simTool;

    //让当前iframe弹层高度适应
    admin.iframeAuto();
    //初始化编辑器

    var E = window.wangEditor;
    var editor = new E('#description_toolbar', '#description_text');
    // 将图片大小限制为 2M
    editor.customConfig.uploadImgMaxSize = 5 * 1024 * 1024;
    editor.customConfig.uploadImgServer =Feng.ctxPath+'/upload/wang'; //'common/batch/imgUpdate';
    editor.customConfig.uploadFileName = 'file';
    editor.customConfig.customAlert = function (info){
        // info 是需要提示的内容
        alert('上传失败，请重试：' + info);
    }
    editor.create();
    BannerInfoDlg.editor = editor;
    //表单提交事件
    //获取详情信息，填充表单
    var isBanner = $("#isBanner");
    form.on('submit(btnSubmit)', function (data) {
        form.render()
        var ajax = new $ax(Feng.ctxPath + "/banner/addItem", function (data) {
            Feng.success("添加成功！");
            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);
            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set("isVideo",$("#isVideo").attr("checked")=="checked"?1:0);
        ajax.set(data.field);
        /* ajax.set("isBanner",isBanner.attr("checked")?1:0);*/
        ajax.set("content",editor.txt.html())
        ajax.start();
    });


    //图片上传
    var sim = new simtool("/upload","#bannerBox");
    sim.uploadImg()

    form.on('radio(way)', function(data){
        console.log(data.value); //得到被选中的值
        console.log(data.othis); //得到美化后的DOM对象
        var oneItem = $(".oneItem");
        var goodsItem = $("#goodsItem");
        var contentItem = $("#contentItem");
        var urlItem = $("#urlItem");
        if(data.value==1){
            oneItem.css("display","none")
            BannerInfoDlg.editor.txt.html("")
            goodsItem.css("display","block")
        }else if(data.value==2) {
            oneItem.css("display","none")
            contentItem.css("display","block")
        }else if(data.value==3) {
            oneItem.css("display","none")
            urlItem.css("display","block")
        }
    });

    /*form.on('switch(isVideo)', function(data){
        console.log(data.elem.checked );
        console.log(data.othis); //得到美化后的DOM对象

        var linkWay = $('input[name="linkWay"]:eq(2)');
        var contentItem = $("#contentItem");
        var urlItem = $("#urlItem");
        var oneItem = $(".oneItem");
        if(data.elem.checked){
            linkWay.attr("checked","checked");
            oneItem.css("display","none")
            urlItem.css("display","block")
            contentItem.css("display","block")
            Feng.disableComponent($('input[name="linkWay"]'),true);
            form.render();

        }else {
            oneItem.css("display","none")
            Feng.disableComponent($('input[name="linkWay"]'),false)
            form.render();
        }
    });*/




});